package com.nulldev.util.graphics.renderIt.util;

import java.awt.GraphicsConfiguration;
import java.util.concurrent.atomic.AtomicInteger;

public class renderItUtils {

	public static int guessTextWidth(final int fontSize, final String s) {
		if (fontSize <= 0 || s == null || s.isEmpty())
			return -1;
		final AtomicInteger tw = new AtomicInteger();
		s.codePoints().mapToObj(cp -> Character.toChars(cp)).forEach(c -> {
			tw.addAndGet(c.length);
		});
		return tw.get() * fontSize;
	}

	public static String getDeviceConfigurationString(final GraphicsConfiguration gc) {
		return "Bounds: " + gc.getBounds() + "\n" + "Buffer Capabilities: " + gc.getBufferCapabilities() + "\n" + "   Back Buffer Capabilities: "
				+ gc.getBufferCapabilities().getBackBufferCapabilities() + "\n" + "      Accelerated: "
				+ gc.getBufferCapabilities().getBackBufferCapabilities().isAccelerated() + "\n" + "      True Volatile: "
				+ gc.getBufferCapabilities().getBackBufferCapabilities().isTrueVolatile() + "\n" + "   Flip Contents: "
				+ gc.getBufferCapabilities().getFlipContents() + "\n" + "   Front Buffer Capabilities: "
				+ gc.getBufferCapabilities().getFrontBufferCapabilities() + "\n" + "      Accelerated: "
				+ gc.getBufferCapabilities().getFrontBufferCapabilities().isAccelerated() + "\n" + "      True Volatile: "
				+ gc.getBufferCapabilities().getFrontBufferCapabilities().isTrueVolatile() + "\n" + "   Is Full Screen Required: "
				+ gc.getBufferCapabilities().isFullScreenRequired() + "\n" + "   Is MultiBuffer Available: "
				+ gc.getBufferCapabilities().isMultiBufferAvailable() + "\n" + "   Is Page Flipping: " + gc.getBufferCapabilities().isPageFlipping() + "\n"
				+ "Device: " + gc.getDevice() + "\n" + "   Available Accelerated Memory: " + gc.getDevice().getAvailableAcceleratedMemory() + "\n"
				+ "   ID String: " + gc.getDevice().getIDstring() + "\n" + "   Type: " + gc.getDevice().getType() + "\n" + "   Display Mode: "
				+ gc.getDevice().getDisplayMode() + "\n" + "Image Capabilities: " + gc.getImageCapabilities() + "\n" + "      Accelerated: "
				+ gc.getImageCapabilities().isAccelerated() + "\n" + "      True Volatile: " + gc.getImageCapabilities().isTrueVolatile() + "\n";
	}

}
